package com.woniu.web.service.impl;

import com.woniu.common.entity.TbJpRole;
import com.woniu.common.entity.TbJpRoleExample;
import com.woniu.web.mapper.TbJpRoleDao;
import com.woniu.web.mapper.TbJpUserDao;
import com.woniu.web.service.TbJpRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
@Service
@Transactional
public class TbJpRoleServiceImpl implements TbJpRoleService {
    @Resource
    TbJpRoleDao roleDao;
    @Override
    public List<TbJpRole> findAllRoles(String roleName) {
        TbJpRoleExample roleExample=new TbJpRoleExample();
        roleExample.setOrderByClause("role_id desc");
        if (roleName != null && !roleName.equals("") && !roleName.equals("null")) {

            roleExample.createCriteria().andRoleNameLike("%" + roleName + "%");


        }
        return roleDao.selectByExample(roleExample);

    }

    @Override
    public void addRole(TbJpRole tbJpRole) {
        roleDao.insert(tbJpRole);
    }

    @Override
    public void delRole(Integer roleId) {
        roleDao.deleteByPrimaryKey(roleId);
    }
    @Override
    public void updateRole(TbJpRole tbJpRole) {
        roleDao.updateByPrimaryKeySelective(tbJpRole);
    }

    @Override
    public void delRoleMore(Integer[] roleIds) {
        TbJpRoleExample roleExample=new TbJpRoleExample();
        roleExample.createCriteria().andRoleIdIn(Arrays.asList(roleIds));
        roleDao.deleteByExample(roleExample);
    }
}
